package com.hxh.wechat.util

import okhttp3.FormBody

/**
 * 动态转化FormBody 工具类
 */
fun <T> T.toFormBody(): FormBody {
    val formBodyBuilder = FormBody.Builder()
    val fields = this!!::class.java.declaredFields
    for (field in fields) {
        field.isAccessible = true
        val value = field.get(this)?.toString() ?: ""
        formBodyBuilder.add(field.name, value)
    }
    return formBodyBuilder.build()
}